package shuiyuqing.fragments;

import android.app.Activity;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ListView;

import com.xkh.xkh.R;

import java.util.ArrayList;

import shuiyuqing.model.BasicInfoModel;
import shuiyuqing.network.beans.IrrBAWaterGate;
import shuiyuqing.network.beans.IrrBTCanalDetail;
import shuiyuqing.views.adapters.ChooseWaterGateAdapter;

/**
 * Created by 凯 on 2015/11/7.
 */
@Deprecated
public class WaterGateDialogFragment extends DialogFragment {

    //
    Delegate delegate;

    // 选中的渠道
    IrrBTCanalDetail detail;

    //
    ListView lv_waterGateSel;

    // 闸门适配
    ChooseWaterGateAdapter chooseWaterGateAdapter;

    public void setDetail(IrrBTCanalDetail detail) {
        this.detail = detail;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = inflater.inflate(R.layout.fragment_watergatesel,null);

        initview(view);
        return view;
    }

    // 初始化
    private void initview(View view) {
        lv_waterGateSel = (ListView) view.findViewById(R.id.id_lv_sel_waterGate);

        chooseWaterGateAdapter = new ChooseWaterGateAdapter();
        chooseWaterGateAdapter.setDetail(detail);

        lv_waterGateSel.setAdapter(chooseWaterGateAdapter);

        lv_waterGateSel.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                IrrBAWaterGate gate = (IrrBAWaterGate) view.getTag(R.id.id_gate);
                dismiss();
                delegate.select(gate);
            }
        });

    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        if (activity instanceof Delegate)
        {
            delegate = (Delegate) activity;
        }
    }

    public static interface Delegate
    {
        public void select(IrrBAWaterGate gate);
    }

}
